home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1997 April / EnigmA AMIGA RUN 17 (1997)(G.R. Edizioni)(IT)[!][issue 1997-04][EAR-CD].iso / EARCD / comm / bbs / citsrc6K05.lha / logedit.c < prev    next >
C/C++ Source or Header  |  1996-10-25  |  11KB  |  408 lines

  1. /*
  2. *                               Logedit.c
  3. *
  4. * Log editor for Citadel-86, V 2.x.
  5. */
  6. /*
  7. *                               history
  8. *
  9. * 89Apr16 HAW  New visual support for PC Clones.  (non-portable)
  10. * 87Oct11 HAW  V3 update.
  11. * 85Nov16 HAW  Modified for MS-DOS libraries.
  12. * 85Aug10 HAW  Created.
  13. */
  14. #include "ctdl.h"    /* header file  */
  15. #include <stdio.h>
  16. #include <string.h>
  17. #include <stdlib.h>
  18. #include <math.h>
  19. #include <ctype.h>
  20. #include <time.h>
  21. #include <proto/exec.h>
  22. #include <dos/dos.h>
  23. #include <pragmas/dos_pragmas.h>
  24. #include "exec/memory.h"
  25. #include "exec/ports.h"
  26. #include "exec/exec.h"
  27. /*
  28. *                               Contents
  29. *
  30. *       crashout()              irrecoverable error
  31. *       getUNumber()            Gets number from console
  32. *       getUtilString()         Gets string from console
  33. *       logSum()                Sums up the log for logTab
  34. *       main()                  Main controller
  35. */
  36. char NoShow = FALSE;
  37. extern CONFIG    cfg;
  38. extern SListBase MailForward;
  39. extern LogTable *logTab;        /* RAM index of pippuls */
  40. extern logBuffer logBuf;        /* Pippul buffer        */
  41. extern FILE     *logfl;       /* log file descriptor    */
  42. extern int      thisLog;
  43. char onConsole=0, remoteSysop=0;
  44.  
  45.  
  46. void getUtilString(char *prompt, char *buf, int lim);
  47. void logSum(void);
  48. void crashout ( char *str );
  49. void handleEditing ( void );
  50. int getUNumber ( char *prompt , unsigned bottom , unsigned top );
  51. void getUtilString ( char *prompt , char *buf , int lim );
  52. int logSort ( LogTable *s1 , LogTable *s2 );
  53. int main ( int argc , char **argv );
  54. void showlog ( void );
  55. void Display_Flag (short,short, char *);
  56.  
  57. /*
  58. * crashout()
  59. *
  60. * This handles an irrecoverable error.
  61. */
  62. void crashout(str)
  63. char *str;
  64.   {
  65.   printf(str);
  66.   exit(10);
  67.  
  68.   }
  69. /*
  70. * handleEditing()
  71. *
  72. * This handles editing accounts in a very primitive manner.
  73. */
  74. void handleEditing()
  75.   {
  76.   char c;
  77.   char mess[40];
  78.   int account;
  79.   label NewName;
  80.   logBuffer lBuf;
  81.   ForwardMail *data;
  82.   initLogBuf(&lBuf);
  83.   printf(" Citadel UserLog Editor %s\n", VERSION_NAME);
  84.   sPrintf(mess, "Which account (%d to quit): ", cfg.MAXLOGTAB);
  85.   account = getUNumber(mess, 0, cfg.MAXLOGTAB);
  86.   getLog(&logBuf, account);
  87.   while (account != cfg.MAXLOGTAB)
  88.     {
  89.     showlog();
  90.     printf("LogEdit Menu\n");
  91.     printf("A - toggle Active Acct   \t S - toggle Aide Status\n");
  92.     printf("E - toggle Expert mode   \t N - toggle Net Privileges\n");
  93.     printf("D - toggle Door Privs    \t L - toggle Download Privileges\n");
  94.     printf("B - toggle Permanent Acct\t F - toggle Floor mode\n");
  95.     printf("T - toggle Twit Status   \t R - toggle Ruggie Status\n");
  96.     printf("C - change user name     \n");
  97.     printf("W - change column width  \t G - Go to New account\n");
  98.     printf("J - change LD Net Credit \t Q - Quit\n");
  99.     c = getchar();
  100.     while( getchar() != '\n');
  101.     switch( c )
  102.       {
  103.       case 'j':     /* Net Credit */
  104.       case 'J':
  105.         sPrintf(mess, "Currently %d credits, Enter New:", logBuf.credit);
  106.         logBuf.credit = (int) getUNumber(mess,1,1000);
  107.         putLog(&logBuf, account);
  108.         break;
  109.       case 'w':
  110.       case 'W':
  111.         sprintf(mess,"Enter new column width(40-80):");
  112.         logBuf.lbwidth = getUNumber(mess,40,80);
  113.         putLog(&logBuf, account);
  114.         break;
  115.       case 'g':
  116.       case 'G': /* go to next account */
  117.         sPrintf(mess, "Which account (%d to quit): ", cfg.MAXLOGTAB);
  118.         account = getUNumber(mess, 0, cfg.MAXLOGTAB);
  119.         getLog(&logBuf, account);
  120.         break;
  121.       case 'a':
  122.       case 'A': /* activate an account */
  123.       if (logBuf.lbflags.L_INUSE != 1)
  124.         {
  125.         logBuf.lbflags.L_INUSE = 1;
  126.  
  127.         }
  128.       else
  129.         {
  130.         logBuf.lbflags.L_INUSE = 0;
  131.         if (SearchList(&MailForward, logBuf.lbname) != NULL)
  132.           {
  133.           KillData(&MailForward, logBuf.lbname);
  134.           UpdateForwarding();
  135.  
  136.           };
  137.  
  138.         };
  139.       putLog(&logBuf, account);
  140.       break;
  141.       case 'q' :
  142.       case 'Q' :  /* Quit */
  143.       return;
  144.       break;
  145.       case 'C' :  /* Change a User's name */
  146.       case 'c' :
  147.       getUtilString("new name", NewName, NAMESIZE);
  148.       if (strLen(NewName) != 0)
  149.         {
  150.         if (findPerson(NewName, &lBuf) != ERROR)
  151.           {
  152.           printf("%s already in use.\n", NewName);
  153.  
  154.           }
  155.         else
  156.           {
  157.           if ((data = SearchList(&MailForward,logBuf.lbname)) != NULL)
  158.             {
  159.             data->UserName = strdup(NewName);
  160.             KillData(&MailForward, logBuf.lbname);
  161.             UpdateForwarding();
  162.  
  163.             };
  164.           strCpy(logBuf.lbname, NewName);
  165.           putLog(&logBuf, account);
  166.  
  167.           };
  168.  
  169.         }
  170.       else printf("No name entered, aborted change\n");
  171.       break;
  172.       case 'S' :
  173.       case 's' :
  174.       logBuf.lbflags.AIDE =  (logBuf.lbflags.AIDE) ? 0 : 1;
  175.       putLog(&logBuf, account);
  176.       break;
  177.       case 'E' :
  178.       case 'e' :
  179.       logBuf.lbflags.EXPERT   = logBuf.lbflags.EXPERT ? 0 : 1;
  180.       putLog(&logBuf, account);
  181.       break;
  182.       case 'N' :
  183.       case 'n' :
  184.       logBuf.lbflags.NET_PRIVS= logBuf.lbflags.NET_PRIVS ? 0 : 1;
  185.       putLog(&logBuf, account);
  186.       break;
  187.       case 'D' :
  188.       case 'd' :
  189.       logBuf.lbflags.DOOR_PRIVS = logBuf.lbflags.DOOR_PRIVS ? 0 : 1;
  190.       putLog(&logBuf, account);
  191.       break;
  192.       case 'L' :
  193.       case 'l' :
  194.       logBuf.lbflags.DL_PRIVS = logBuf.lbflags.DL_PRIVS ? 0 : 1;
  195.       putLog(&logBuf, account);
  196.       break;
  197.       case 'B' :
  198.       case 'b' :
  199.       logBuf.lbflags.PERMANENT= logBuf.lbflags.PERMANENT ? 0 : 1;
  200.       putLog(&logBuf, account);
  201.       break;
  202.       case 'F' :
  203.       case 'f' :
  204.       logBuf.lbflags.FLOORS   = logBuf.lbflags.FLOORS ? 0 : 1;
  205.       putLog(&logBuf, account);
  206.       break;
  207.       case 'T' :
  208.       case 't' :
  209.       logBuf.lbflags.TWIT     = logBuf.lbflags.TWIT   ? 0 : 1;
  210.       putLog(&logBuf, account);
  211.       break;
  212.       case 'R' :
  213.       case 'r' :
  214.       logBuf.lbflags.RUGGIE   = logBuf.lbflags.RUGGIE ? 0 : 1;
  215.       putLog(&logBuf, account);
  216.       break;
  217.       Default:  printf("Invalid function Choice\n");
  218.  
  219.       };
  220.  
  221.     };
  222.   /* Loop until User enters Quit */
  223.  
  224.   }
  225. /*
  226. * getUNumber()
  227. *
  228. * This prompts for a number in (bottom, top) range.
  229. */
  230. int getUNumber(prompt, bottom, top)
  231. char   *prompt;
  232. unsigned bottom;
  233. unsigned top;
  234.   {
  235.   unsigned try;
  236.   char numstring[NAMESIZE];
  237.   do
  238.     {
  239.     getUtilString(prompt, numstring, NAMESIZE);
  240.     try     = atoi(numstring);
  241.     if (try < bottom)  printf("Sorry, must be at least %d\n", bottom);
  242.     if (try > top   )  printf("Sorry, must be no more than %d\n", top);
  243.  
  244.     }
  245.   while (try < bottom ||  try > top);
  246.   return (int)try;
  247.  
  248.   }
  249. /*
  250. * getUtilString()
  251. *
  252. * This function gets a string from the user.
  253. */
  254. void getUtilString(prompt, buf, lim)
  255. char *prompt;
  256. char *buf;
  257. int  lim;       /* max # chars to read */
  258.   {
  259.   char *c;
  260.   short x;
  261.   printf("Enter %s:", prompt, lim);
  262.   c = fgets(buf,lim,stdin);
  263.   for(x=0; x<lim;x++)if( buf[x] == '\n')buf[x] = '\0';
  264.   printf("\n");
  265.  
  266.   }
  267. /*
  268. * logSort()
  269. *
  270. * This is used for sorting the log.
  271. */
  272. int logSort(s1, s2)
  273. LogTable *s1, *s2;
  274.   {
  275.   if (s1->ltnmhash == 0 && s2->ltnmhash == 0)
  276.   return 0;
  277.   if (s1->ltnmhash == 0 && s2->ltnmhash != 0)
  278.   return 1;
  279.   if (s1->ltnmhash != 0 && s2->ltnmhash == 0)
  280.   return -1;
  281.   if (s1->ltnewest < s2->ltnewest)
  282.   return 1;
  283.   if (s1->ltnewest > s2->ltnewest)
  284.   return -1;
  285.   return 0;
  286.  
  287.   }
  288. /*
  289. * logSum()
  290. *
  291. * This goes through the log to correct logTab.
  292. */
  293. void logSum()
  294.   {
  295.   int i;
  296.   int logSort();
  297.   int count = 0;
  298.   #ifdef WORKS
  299.   if (rewind(logfl) != 0) crashout("Rewinding logfl failed!");
  300.   #else
  301.   rewind(logfl);
  302.   #endif
  303.   /* clear logTab */
  304.   for (i = 0;i < cfg.MAXLOGTAB;i++) logTab[i].ltnewest = 0l;
  305.   /* load logTab: */
  306.   for (thisLog = 0;thisLog < cfg.MAXLOGTAB;thisLog++)
  307.     {
  308.     getLog(&logBuf, thisLog);
  309.     /* count valid entries:     */
  310.     if (logBuf.lbflags.L_INUSE)
  311.       {
  312.       if (strLen(logBuf.lbname) >= NAMESIZE ||
  313.       strLen(logBuf.lbpw) >= NAMESIZE )
  314.         {
  315.         logBuf.lbflags.L_INUSE = FALSE;
  316.         putLog(&logBuf, thisLog);
  317.  
  318.         }
  319.       else
  320.         {
  321.         count++;
  322.  
  323.         }
  324.  
  325.       };
  326.     /* copy relevant info into index:   */
  327.     logTab[thisLog].ltnewest = logBuf.lbvisit[0];
  328.     logTab[thisLog].ltlogSlot= thisLog;
  329.     if (logBuf.lbflags.L_INUSE == 1)
  330.       {
  331.       logTab[thisLog].ltnmhash = hash(logBuf.lbname);
  332.       logTab[thisLog].ltpwhash = hash(logBuf.lbpw  );
  333.       logTab[thisLog].ltpermanent = logBuf.lbflags.PERMANENT;
  334.  
  335.       }
  336.     else
  337.       {
  338.       logTab[thisLog].ltnmhash = 0;
  339.       logTab[thisLog].ltpwhash = 0;
  340.  
  341.       }
  342.  
  343.     }
  344.   printf(" logInit--%d valid log entries\n", count);
  345.   qsort((char *)logTab, cfg.MAXLOGTAB, cfg.sizeLTentry, logSort);
  346.  
  347.   }
  348. /*
  349. * main()
  350. *
  351. * Main controller.
  352. */
  353. main(argc, argv)
  354. int argc;
  355. char **argv;
  356.   {
  357.   SYS_FILE logfile;
  358.   printf("LOGEDIT V3.42\n%s\n", COPYRIGHT);
  359.   cfg.weAre = UTILITY;
  360.   if (!readSysTab(FALSE, TRUE)) exit(1);
  361.   if (access(LOCKFILE, 0) != -1)
  362.     {
  363.     printf("Please do not run LogEdit from Outside Commands.\n");
  364.     writeSysTab();
  365.     exit(1);
  366.  
  367.     }
  368.   makeSysName(logfile, "ctdllog.sys", &cfg.logArea);
  369.   openFile(logfile, &logfl);
  370.   initLogBuf(&logBuf);
  371.   makeSysName(logfile, "ctdlfwd.sys", &cfg.roomArea);
  372.   MakeList(&MailForward, logfile, NULL);
  373.   handleEditing();
  374.   logSum();
  375.   writeSysTab();
  376.   return 0;
  377.   }
  378. void showlog()
  379.   {
  380.   char *LastOn(long lastdate, char s);
  381.   printf(" %-20s",logBuf.lbname);
  382.   printf("%8ld", logBuf.lbvisit[0]);
  383.   printf(" %d columns. Date:%s\n",logBuf.lbwidth,LastOn(logBuf.lblaston, TRUE));
  384.   Display_Flag(0,logBuf.lbflags.AIDE       ,"AIDE Status        ");
  385.   Display_Flag(1,logBuf.lbflags.EXPERT     ,"Expert User        ");
  386.   Display_Flag(0,logBuf.lbflags.NET_PRIVS  ,"Network Privileges ");
  387.   Display_Flag(1,logBuf.lbflags.DOOR_PRIVS ,"Door Privileges    ");
  388.   Display_Flag(0,logBuf.lbflags.DL_PRIVS   ,"Download Privileges");
  389.   Display_Flag(1,logBuf.lbflags.PERMANENT  ,"Permanent Account  ");
  390.   Display_Flag(0,logBuf.lbflags.FLOORS     ,"Floor mode         ");
  391.   Display_Flag(1,logBuf.lbflags.TWIT       ,"TWIT User          ");
  392.   Display_Flag(0,logBuf.lbflags.RUGGIE     ,"RUGGIE User        ");
  393.   Display_Flag(1,logBuf.lbflags.L_INUSE    ,"Active Account     ");
  394.   Display_Flag(0,logBuf.lbflags.LFMASK     ,"LF FLAG            ");
  395.   Display_Flag(1,logBuf.lbflags.OLDTOO     ,"OLD STYLE          ");
  396.   Display_Flag(0,logBuf.lbflags.HALF_DUP   ,"HALF DUPLEX        ");
  397.   Display_Flag(1,logBuf.lbflags.ALT_RE     ,"ALT. Read Messages ");
  398.   Display_Flag(0,logBuf.lbflags.NoPrompt   ,"Room Name Prompt   ");
  399.   printf("\n");
  400.   }
  401. void Display_Flag(flag,bit,text)
  402. short  flag, bit;
  403. char  *text;
  404.   {
  405.   printf(" %s: %s%c",text,(bit ? "Yes" : "No "), (flag==0 ? '\t':'\n'));
  406.  
  407.   }
  408.